import { getToken } from "@/utils/auth";
import { Route, Redirect } from "react-router-dom";

const AuthRoute = ({ component: Component, ...rest }) => {
    const token = getToken()
    return (
        <Route {...rest} render={(props) => {
            if (token) {
                return <Component></Component>
            } else {
                return <Redirect to={{
                    pathname: "/login",
                    state: { from: props.location.pathname }
                }}></Redirect>
            }
        }}></Route>
    )
}

export default AuthRoute